package tech.aistar.corejava.day15;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/8/3
 * @Version: 1.0
 */
public class CallableDemo {
    public static void main(String[] args) {
        //1. 创建一个线程池对象 - 缓存了很多线程
        ExecutorService executor = Executors.newCachedThreadPool();

        //2.创建线程对象
        C1 c = new C1();
    }

}
class C1 implements Callable<Integer>{
    @Override
    public Integer call(){
        System.out.println("子线程正在执行...");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        int sum = 0;

        for (int i = 0; i <= 100; i++) {
            sum += i;
        }
        return sum;
    }

}
